package com.chen.springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.springboot.common.AuthAccess;
import com.chen.springboot.common.Result;
import com.chen.springboot.entity.ItemDetail;
import com.chen.springboot.service.ItemDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@Api(tags = {"商品详情接口"})
@RestController
@RequestMapping("/itemDetail")
public class ItemDetailController {

    @Resource
    private ItemDetailService itemDetailService;

    @ApiOperation("通过商品ID获得商品的详情")
    @AuthAccess
    @GetMapping
    public Result<?> findById(@RequestParam Long id){
        ItemDetail data= itemDetailService.findById(id);
        return Result.success(data);
    }

    @ApiOperation("获取商品详情")
    @GetMapping("/getAll")
    public Result<?> getAll(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            @RequestParam(defaultValue = "") String search){
        Page<ItemDetail> data=itemDetailService.getAll(pageNum,pageSize,search);
        return Result.success(data);
    }

    @ApiOperation("删除商品详情")
    @DeleteMapping("{id}")
    public Result<?> delete(@PathVariable("id") Long id){
        itemDetailService.delete(id);
        return Result.success();
    }

    @ApiOperation("添加商品详情")
    @PostMapping
    public Result<?> add(@RequestBody ItemDetail itemDetail){
        itemDetailService.add(itemDetail);
        return Result.success();
    }

    @ApiOperation("更新商品详情")
    @PutMapping
    public Result<?> update(@RequestBody ItemDetail itemDetail){
        itemDetailService.update(itemDetail);
        return Result.success();
    }
}
